import request from '@/utils/request';

// 用户性别枚举
export enum UserGenderEnum {
  UNKNOWN = 0, // 未知
  MALE = 1,    // 男
  FEMALE = 2,  // 女
}

// 用户状态枚举
export enum UserStatusEnum {
  DISABLED = 0, // 停用
  ENABLED = 1,  // 正常
}

// 是否管理员枚举
export enum IsAdminEnum {
  NO = 0,  // 否
  YES = 1, // 是
}

// 用户接口
export interface User {
  id?: number;
  username: string;
  password?: string;
  nickName?: string;
  realName?: string;
  avatar?: string;
  email?: string;
  mobile?: string;
  gender?: UserGenderEnum;
  genderName?: string;
  deptId?: number;
  deptName?: string;
  status?: UserStatusEnum;
  statusName?: string;
  loginIp?: string;
  loginDate?: string;
  isAdmin?: IsAdminEnum;
  remark?: string;
  createTime?: string;
  updateTime?: string;
  createBy?: string;
  updateBy?: string;
  roleIds?: number[];
}

// 用户查询参数
export interface UserQueryParams {
  username?: string;
  mobile?: string;
  status?: UserStatusEnum;
  current?: number;
  size?: number;
}

// 获取用户列表
export function getUserList(params: UserQueryParams) {
  return request.get('/api/user/page', params);
}

// 获取用户详情
export function getUserDetail(userId: number) {
  return request.get(`/api/user/${userId}`);
}

// 创建用户
export function createUser(data: User) {
  return request.post('/api/user', data);
}

// 更新用户
export function updateUser(data: User) {
  return request.put(`/api/user`, data);
}

// 删除用户
export function deleteUser(userId: number) {
  return request.delete(`/api/user/${userId}`);
}

// 更新用户状态
export function updateUserStatus(userId: number, status: UserStatusEnum) {
  return request.put(`/api/user/${userId}/status`, { status });
}

// 启用用户
export function enableUser(userId: number) {
  return request.put(`/api/user/${userId}/enable`);
}

// 禁用用户
export function disableUser(userId: number) {
  return request.put(`/api/user/${userId}/disable`);
}

// 重置用户密码
export function resetUserPassword(userId: number, password: string) {
  return request.put(`/api/user/${userId}/password`, { newPassword: password });
} 